package com.zmm.huoqiumaishou.ui.fragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;


/**
 * 生产fragment的工厂
 */
public class FragmentFactory {
    private static final int FRAGMENT_SUBSCRIBE = 0;
    private static final int FRAGMENT_FOUND = 1;
    private static final int FRAGMENT_ME = 2;
    private static SparseArray<Fragment> fragments = new SparseArray<>();

    //创建一个工厂方法,用来创建一个Fragment对象
    public static Fragment cerateFragment(int index) {
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case FRAGMENT_SUBSCRIBE:
                    fragment = new SubscribeFragment();
                    break;
                case FRAGMENT_FOUND:
                    fragment = new FoundFragment();
                    break;
                case FRAGMENT_ME:
                    fragment = new MeFragment();
                    break;
            }
        }
        return fragment;
    }

}
